package org.digitarts.rtms.spring.collectors.formatter;

import org.springframework.beans.factory.BeanFactory;

public class DeferredFormatter implements IFormatter
{

	protected BeanFactory	beanFactory	= null;
	protected String		beanName	= null;
	protected IFormatter	formatter	= null;

	public DeferredFormatter(String beanName)
	{
		super();
		this.beanName = beanName;
	}

	public String format(Object target)
	{
		if (formatter == null)
		{
			formatter = (IFormatter) beanFactory.getBean(beanName);
		}
		return formatter.format(target);
	}

	public String getBeanName()
	{
		return beanName;
	}

	public void setBeanName(String beanName)
	{
		this.beanName = beanName;
	}

	public BeanFactory getBeanFactory()
	{
		return beanFactory;
	}

	public void setBeanFactory(BeanFactory beanFactory)
	{
		this.beanFactory = beanFactory;
	}

}
